</method>
<method name="ScreenshotWindow">
<arg type="b" direction="in" name="include_frame"/>
+ <arg type="b" direction="in" name="include_cursor"/>
<arg type="b" direction="in" name="flash"/>
<arg type="s" direction="in" name="filename"/>
<arg type="b" direction="out" name="success"/>
</method>
<method name="Screenshot">
+ <arg type="b" direction="in" name="include_cursor"/>
<arg type="b" direction="in" name="flash"/>
<arg type="s" direction="in" name="filename"/>
<arg type="b" direction="out" name="success"/>
* @y: The Y coordinate of the area
* @width: The width of the area
* @height: The height of the area
+ * @flash: Whether to flash the area or not
* @filename: The filename for the screenshot
*
* Takes a screenshot of the passed in area and saves it
/**
* ScreenshotWindow:
* @include_frame: Whether to include the frame or not
+ * @include_cursor: Whether to include the cursor image or not
+ * @flash: Whether to flash the window area or not
* @filename: The filename for the screenshot
*
* Takes a screenshot of the focused window (optionally omitting the frame)
*
*/
ScreenshotWindowAsync : function (params, invocation) {
- let [include_frame, flash, filename] = params;
- global.screenshot_window (include_frame, filename,
+ let [include_frame, include_cursor, flash, filename] = params;
+ global.screenshot_window (include_frame, include_cursor, filename,
Lang.bind(this, this._onScreenshotComplete,
flash, invocation));
},
/**
* Screenshot:
* @filename: The filename for the screenshot
+ * @include_cursor: Whether to include the cursor image or not
+ * @flash: Whether to flash the screen or not
*
* Takes a screenshot of the whole screen and saves it
* in @filename as png image, it returns a boolean
*
*/
ScreenshotAsync : function (params, invocation) {
- let [flash, filename] = params;
- global.screenshot(filename,
+ let [include_cursor, flash, filename] = params;
+ global.screenshot(include_cursor, filename,
Lang.bind(this, this._onScreenshotComplete,
flash, invocation));
},
data, (cairo_destroy_func_t)g_free);
}
+static void
+_draw_cursor_image (cairo_surface_t *surface,
+ cairo_rectangle_int_t area)
+{
+ XFixesCursorImage *cursor_image;
+
+ cairo_surface_t *cursor_surface;
+ cairo_region_t *screenshot_region;
+ cairo_t *cr;
+
+ guchar *data;
+ int stride;
+ int i, j;
+
+ cursor_image = XFixesGetCursorImage (clutter_x11_get_default_display ());
+
+ if (!cursor_image)
+ return;
+
+ screenshot_region = cairo_region_create_rectangle (&area);
+
+ if (!cairo_region_contains_point (screenshot_region, cursor_image->x, cursor_image->y))
+ {
+ XFree (cursor_image);
+ cairo_region_destroy (screenshot_region);
+ return;
+ }
+
+ cursor_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, cursor_image->width, cursor_image->height);
+
+ /* The pixel data (in typical Xlib breakage) is longs even on
+ * 64-bit platforms, so we have to data-convert there. For simplicity,
+ * just do it always
+ */
+ data = cairo_image_surface_get_data (cursor_surface);
+ stride = cairo_image_surface_get_stride (cursor_surface);
+ for (i = 0; i < cursor_image->height; i++)
+ for (j = 0; j < cursor_image->width; j++)
+ *(guint32 *)(data + i * stride + 4 * j) = cursor_image->pixels[i * cursor_image->width + j];
+
+ cairo_surface_mark_dirty (cursor_surface);
+
+ cr = cairo_create (surface);
+ cairo_set_source_surface (cr,
+ cursor_surface,
+ cursor_image->x - cursor_image->xhot - area.x,
+ cursor_image->y - cursor_image->yhot - area.y);
+ cairo_paint (cr);
+
+ cairo_destroy (cr);
+ cairo_surface_destroy (cursor_surface);
+ cairo_region_destroy (screenshot_region);
+ XFree (cursor_image);
+}
+
static void
grab_screenshot (ClutterActor *stage,
_screenshot_data *screenshot_data)
screenshot_data->screenshot_area.width = width;
screenshot_data->screenshot_area.height = height;
+ if (screenshot_data->include_cursor)
+ _draw_cursor_image (screenshot_data->image, screenshot_data->screenshot_area);
+
g_signal_handlers_disconnect_by_func (stage, (void *)grab_screenshot, (gpointer)screenshot_data);
result = g_simple_async_result_new (NULL, on_screenshot_written, (gpointer)screenshot_data, grab_screenshot);
/**
* shell_global_screenshot:
* @global: the #ShellGlobal
+ * @include_cursor: Whether to include the cursor or not
* @filename: The filename for the screenshot
* @callback: (scope async): function to call returning success or failure
* of the async grabbing
*/
void
shell_global_screenshot (ShellGlobal *global,
+ gboolean include_cursor,
const char *filename,
ShellGlobalScreenshotCallback callback)
{
data->global = global;
data->filename = g_strdup (filename);
data->callback = callback;
+ data->include_cursor = include_cursor;
stage = CLUTTER_ACTOR (meta_plugin_get_stage (global->plugin));
* shell_global_screenshot_window:
* @global: the #ShellGlobal
* @include_frame: Whether to include the frame or not
+ * @include_cursor: Whether to include the cursor or not
*
* @filename: The filename for the screenshot
* @callback: (scope async): function to call returning success or failure
void
shell_global_screenshot_window (ShellGlobal *global,
gboolean include_frame,
+ gboolean include_cursor,
const char *filename,
ShellGlobalScreenshotCallback callback)
{
stex = META_SHAPED_TEXTURE (meta_window_actor_get_texture (META_WINDOW_ACTOR (window_actor)));
screenshot_data->image = meta_shaped_texture_get_image (stex, &clip);
+ if (include_cursor)
+ _draw_cursor_image (screenshot_data->image, screenshot_data->screenshot_area);
+
result = g_simple_async_result_new (NULL, on_screenshot_written, (gpointer)screenshot_data, shell_global_screenshot_window);
g_simple_async_result_run_in_thread (result, write_screenshot_thread, G_PRIORITY_DEFAULT, NULL);
g_object_unref (result);